package com.gregbugaj.nativequeryidl.converters;
/**
 * Boolean converter
 * @author greg
 *
 */
public class BooleanConverter implements Converter<Boolean> {
	
	public boolean canConvert(Class<?> type) {		
		return (type == Boolean.class || type == boolean.class);
	}

	/**
	 *  should be able to convert 
	 * 	true/false string as well as
	 *   1/0 to boolean representation
	 */	
	public Boolean convert(Object obj) {
		if(obj==null){
			return false;
		}
		String value=obj.toString();
		if("true".equals(value) || "1".equals(value)){
			return true;
		}else if("false".equals(value) || "0".equals(value)){
			return false;
		}
		return false;
	}


}
